function poetryDetailById(poetryId){
    window.location.href='/page/service/poetry/poetryDetail?params=' + poetryId;
}
function authorDetailById(authorId){
    window.location.href='/page/service/author/authorDetail?params=' + authorId;
}
function saveAuthor(authorId){
    window.location.href='/page/service/author/saveAuthor?params=' + authorId;
}
function userDetailById(userId){
    window.parent.location.href='/page/service/user/userDetail?params=' + userId;
}
function tipsMessage(json) {
    alert(`错误码：${json.code}${json.message}`);
}
function initCode(type, obj, flag, defaultValue, rollback) {
    $.ajax({
        url: `/code/getCodesByType?type=${type}`,
        dataType: "json",
        type: "GET",
        success: function (json) {
            let arr = json.data;
            initCodeByArr(arr, obj, flag, defaultValue);
            if(rollback){
                rollback.apply();
            }
        }
    });
}
function initCodeByArr(arr, obj, flag, defaultValue) {
    let html = `<option value=${defaultValue}>---请选择---</option>`;
    for(let i = 0, j = arr.length; i < j; i ++){
        let o = arr[i];
        let value = flag ? o.value: o.code;
        html += `<option value=${value}>${o.value}</option>`;
    }
    obj.html(html);
}
const CURRENT_USER = "currentUser";
function setUser() {
    $.ajax({
        url: "/page/currentUser",
        dataType: "json",
        type: "GET",
        success: function (res) {
            res = JSON.stringify(res);
            sessionStorage.setItem(CURRENT_USER, res);
        }
    });
}
function getUser() {
    let user = sessionStorage.getItem(CURRENT_USER);
    return user ? JSON.parse(user) : user;
}
function logout() {
    if(confirm("是否退出系统？")){
        $.ajax({
            url: "/login/logout",
            dataType: "json",
            type: "GET",
            success: function (res) {
                if(res.code === 200){
                    sessionStorage.removeItem(CURRENT_USER);
                    window.parent.location.href = "/page/index";
                }else{
                    alert(res.message);
                }
            },
            error: function () {
                alert("退出失败，请检查网络！！！");
            }
        });
    }
}
function formatParam(param) {
    return param.replaceAll("'", "\\'");
}
const BACK_MAIN_PAGE = "authorKey", BACK_KEY = "backKey";
function setBackPageIsMainPageFlag() {
    sessionStorage.setItem(BACK_KEY, BACK_MAIN_PAGE);
}
function defaultBackPage() {
    sessionStorage.setItem(BACK_KEY, "");
}
function lastPage() {
    let page = sessionStorage.getItem(BACK_KEY);
    if(page === BACK_MAIN_PAGE){
        window.parent.location.href = "/page/service/index";
    }else{
        window.parent.history.back();
    }
}
function replaceKeyWord(answer, keyWord) {
    return answer.replaceAll(keyWord, `<span class="keyword-span">${keyWord}</span>`);
}